Resource Caching Reference
As of 23.1+, the RESTful engine has the ability to store templates, and then load them into memory for better performance, as well as eliminating the need to always include the template in all your requests. The way it works is we have a template repository that you can add templates to, and when you use that template for the first time, it loads it in memory.
It works the same for resources that you import into your templates. You can utilize this cache to also store your imported resources.
Adding a Resource
To add a template to the template repository, use the POST v2/templates
endpoint. The templates
endpoint deals with the CachedResource
model for the request body. The model contains the following:
ResourceID
: The identifier associated with the template. This will be used later to call on the stored template.ConnectionString
: This is the connection string to the template if it is hosted somewhere. (Either populate the ConnectionString or the Data, not both)Data
: Is the base64 encoded data of the template (Either populate Data or ConnectionString, not both)FileType
: Is the file type of the file you are adding to the cache. If it is yourdocx
template, then this value will bedocx
. (You can see this in our SwaggerDocumentation)
Here is an example of a request body that makes use of the ConnectionString
<CachedResource>
<ConnectionString>https://windward-private-bucket.s3.amazonaws.com/Southwind_JSON.docx</ConnectionString>
<ResourceID>testing</ResourceID>
<FileType>docx</FileType>
</CachedResource>
Take note of the ResourceID
you select because that's how you will interact with the stored template. By default, the templates are stored in the App_Data/cahce/
directory in your RESTful install.
Using a Stored Resource
In order to use a stored template when posting a request for processing, you will need to supply the following URI in the ConnectionString entry in the request body:
file://resources/{RESOURCE_ID}
Where {RESOURCE_ID}
is the ResourceID you assigned when adding the template to the template repository. Here is an example request body using the template we added in the previous section:
<Template>
<ConnectionString>file://resources/testing</ConnectionString>
<OutputFormat>pdf</OutputFormat>
<Datasources>
<Datasource>
.
.
.
</Datasource>
</Datasources>
</Template>
What this does is it tells the RESTful engine to check if the template is already loaded in memory. If it is not, it will check the template repository to see if that template exists. If it does, then it will load the template into memory and use that. For all requests going forward that use this template, the engine will use the template loaded in memory for better performance (unless the cache was cleared, covered in a later section).
Getting a Resource from the Template Store
If you want to get a template stored in the template repository, you can make use of the GET /v2/templates/{RESOURCE_ID}
endpoint. This endpoint, upon successful execution, will return a CachedResource
with the template ResourceID as well as the template Data as a base64 encoded string.
Deleting a Resource from the Template Store
If you want to delete a template stored from the template repository, you can make use of the DELETE /v2/templates/{RESOURCE_ID}
endpoint. This endpoint, upon successful execution, will delete the template associated with the provided RESOURCE_ID
will delete the template from the template storage.
This endpoint does not remove templates from memory, only from the template storage. Templates are removed from memory when the cache is cleared (covered in the next section).
Using a Cached Resource in Your Template
As mentioned, you can now store your imported resources in the resource cache. In order to do this you must first cache the resource following the steps above to add the file to the cache. Once youve done that, go to the import tag in your template, and set the connection string as the select:
file://resources/{RESOURCE_ID}
Where {RESOURCE_ID} is the id you set when adding the resource to the cache. And thats it! Your template can now utilize cached resources in the RESTful engine to help with performance.
Clearing the Cache
In order to clear the cache, we have a properly called mins-clear-cache
. This property determines how often the templates are cleared from memory, and defaults to 5 minutes. If you want to change how frequently the cache is cleared, please change this property.
To set the property in the .NET RESTful Engine:
- In the
<AppSettings>
section of theWeb.config
file for the RESTful engine, add the following:
<add key="mins-clear-cache" value="" />
To set the property in the Java RESTful Engine:
- In the WindwardReports.properties file for the RESTful engine, add the following:
mins-clear-cache=XX
Where XX is the number of minutes you want the cache to clear after